define(["vue", "axios"], function (Vue, axios) {

    Vue.component("dictionary", {
        template: '<select v-model="value" v-on:change="selectChange"><option v-for="item in result" v-bind:value="item.code">{{item.name}}</option></select>',
        props: {
            value: Date,
            type: String,
            code: {
                default: false
            }
        },
        data: function () {
            return {
                result: []
            }
        },
        mounted: function () {
            var self = this;
            axios.get("/common/dict?typeCode=" + self.type)
                .then(function (response) {
                    if (!self.code) {
                        for (var i = 0; i < response.data.length; i++) {
                            response.data[i].code = response.data[i].name;
                        }
                    }
                    self.result = response.data;
                });
        },
        methods: {
            selectChange: function () {
                this.$emit("input", this.value);
            }
        }
    });
});